# Python 2.6.4
# Project Euler, Problem 81
# Copyright 2010 Talha Zaman

M = [[int(y) for y in x.strip().split(',')] for x in open("matrix.txt").readlines()]
dim = len(M)
for i in range(1,2*dim+1):
    if (i<dim):
        M[0][i] += M[0][i-1]
        M[i][0] += M[i-1][0]
    for j in range(1,i):
        if j>=dim or i-j>=dim: continue
        M[j][i-j] += min(M[j-1][i-j], M[j][i-j-1])
print M[dim-1][dim-1]
